//
//  WEXRetweetStatusView.swift
//  microBlog
//
//  Created by apple on 16/4/21.
//  Copyright © 2016年 Hill. All rights reserved.
//

import UIKit
import SnapKit
import YYText

class WEXRetweetStatusView: UIView {
    
    
//    设置记录view的底部约束属性
    var bottomViewCons: Constraint?
    
//    设置外部传值属性
    var statusViewModel: WEXStatusViewModel? {
        
        didSet{
            
//            lb_content.text = statusViewModel?.contentText
            lb_content.attributedText = statusViewModel?.retweetAttributedString
            
//            取消视图底部约束
            bottomViewCons?.uninstall()
            
            if let pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls where pic_urls.count > 0 {
                
                
//                设置单图的地址和尺寸
                v_pictureView.dataInfo = (pic_urls,statusViewModel!.retweetPicSize)
                
//                设置配图的尺寸
                v_pictureView.snp_updateConstraints(closure: { (make) -> Void in
                    
                    make.size.equalTo(statusViewModel!.retweetPicSize)
                })
                
                
                
//                传值
//                v_pictureView.pic_urls = pic_urls
                
//                设置图片界面非隐藏状态
                v_pictureView.hidden = false
                
//                设置底部约束为图片底部
                self.snp_updateConstraints(closure: { (make) -> Void in
                    
                  bottomViewCons = make.bottom.equalTo(v_pictureView.snp_bottom).offset(commonMargin).constraint
                    
                })
                
                
                
            }else{
                
                v_pictureView.hidden = true
                
                self.snp_updateConstraints(closure: { (make) -> Void in
                    
                  bottomViewCons = make.bottom.equalTo(lb_content).offset(commonMargin).constraint
                })
            }
            
        }
    }

    override init(frame: CGRect) {
        
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

    // MARK: - 设置UI界面
    private func setupUI() {
        
        backgroundColor = UIColor(white: 180 / 255.0 , alpha: 1)
//        添加转发内容
        addSubview(lb_content)
        
//        添加配图
        addSubview(v_pictureView)
        
//        转发内容的约束
        lb_content.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.equalTo(self).offset(commonMargin)
            
        }
        
        v_pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(lb_content.snp_bottom).offset(commonMargin)
            
            make.leading.equalTo(lb_content)
            
            make.size.equalTo(CGSizeMake(100, 100))
            
        }
        
        self.snp_makeConstraints { (make) -> Void in
            
         bottomViewCons = make.bottom.equalTo(v_pictureView.snp_bottom).offset(commonMargin).constraint
            
        }
        
        
    }
    
    // MARK: - 懒加载子控件
    // 正文label
    private lazy var lb_content: YYLabel = {
        
//        let content = UILabel(textColor: UIColor.darkGrayColor(), textFont: contentFont, preferredMaxLayoutWidth: SCREENWIDTH - 2 * commonMargin)
//        
//        return content
        
        let label = YYLabel()
        
        label.userInteractionEnabled = true
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(contentFont)
        label.preferredMaxLayoutWidth = SCREENWIDTH - 2 * commonMargin
        label.numberOfLines = 0
        
        
        return label

        
    }()
    
    // 图片view
    private lazy var v_pictureView: WEXPictureView = WEXPictureView.init(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
}
